package nl.samenloop.bigscreen.component;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JLabel;

import nl.samenloop.bigscreen.BigScreen;
import nl.samenloop.bigscreen.fx.Transparency;

@SuppressWarnings("serial")
public class TransparentLabel extends JLabel implements Transparency {

	private float opacity = 0.0f;

	public TransparentLabel(String text) {
		super(text);
		setOpaque(false);
	}

	public TransparentLabel() {
		super();
		setOpaque(false);
	}

	@Override
	public float getOpacity() {
		return opacity;
	}

	@Override
	public void setOpacity(float opacity) {
		this.opacity = opacity;
	}

	public void paint(Graphics g) {
		if (g != null) {
			Graphics2D g2 = (Graphics2D) g.create();

			g2.setBackground(Color.BLACK);
			g2.clearRect(0, 0, getWidth(), getHeight());

			g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));

			super.paint(g2);

			g2.dispose();
		}

	}
}